-
Notifications
You must be signed in to change notification settings - Fork 587
feat: add identity-based credits OpenAPI specifications #4192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add identity-based credits OpenAPI specifications #4192
Conversation
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 📝 WalkthroughWalkthroughThis change refactors credit-related schemas and types across identities and keys in the OpenAPI specification and generated Go code. It introduces consolidated types (CreditInterval, CreditOperation, Credits, UpdateCredits, VerifyKeyIdentity) replacing key-specific variants, and integrates credits handling at both identity and key levels with new endpoints and modified request/response structures. Changes
Sequence DiagramsequenceDiagram
participant Client
participant API
participant Handler
rect rgb(200, 220, 255)
Note over Client,Handler: Identity-Level Credits Update (new)
Client->>API: POST /v2/identities.updateCredits<br/>(identity, operation, value)
API->>Handler: updateIdentityCredits<br/>(CreditOperation: set|increment|decrement)
Handler->>Handler: Apply operation to identity credits<br/>(value or null for unlimited)
Handler-->>API: Credits updated<br/>(remaining, refill)
API-->>Client: 200 OK<br/>V2IdentitiesUpdateCreditsResponseBody
end
rect rgb(220, 200, 255)
Note over Client,Handler: Key-Level Credits Update (refactored)
Client->>API: PATCH /v2/keys/{keyId}/updateCredits<br/>(operation, value)
API->>Handler: updateKeyCredits<br/>(CreditOperation: set|increment|decrement)
Handler->>Handler: Apply operation to key credits<br/>(or identity-level credits if prioritized)
Handler-->>API: Credits updated<br/>(Credits type)
API-->>Client: 200 OK<br/>V2KeysUpdateCreditsResponseBody
end
rect rgb(200, 255, 220)
Note over Client,Handler: Key Verification (identity shape refined)
Client->>API: GET /v2/keys/{key}/verify
API->>Handler: verifyKey
Handler->>Handler: Validate key & retrieve identity
Handler-->>API: VerifyKeyIdentity<br/>(id, externalId, meta, ratelimits)
API-->>Client: 200 OK<br/>V2KeysVerifyKeyResponseData<br/>(includes VerifyKeyIdentity)
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Areas requiring extra attention:
Possibly related PRs
Suggested labels
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ce27d21 to
19aadaf
Compare
19aadaf to
03872fb
Compare
c300f90 to
aa1950a
Compare
03872fb to
6816e5e
Compare
aa1950a to
baf6928
Compare
6816e5e to
c199c71
Compare
c199c71 to
7397a54
Compare
3369e55 to
8d4a3a4
Compare
d36dc6b to
a4949f4
Compare
a4949f4 to
0b8dcae
Compare
0b8dcae to
b4cfb6c
Compare
| - object | ||
| - null | ||
| description: Configuration for automatic credit refill behavior. | ||
| - "null" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this null to "null" typo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"null" and null is basically the same
| When a key belonging to this identity is verified, credits are deducted from the identity's balance rather than individual key limits. | ||
| Essential for implementing usage-based billing and quota management at the user or organization level. | ||
| Identity credits take priority over key-level credits during verification. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does this mean? are key credits still deducted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Key credits are only deducted if the attached identity has no credits which means unlimited and the key has credits.
If the key has a identity with credits, we are going to decrement the credits of the identity
| **Side Effects** | ||
| Credit updates take effect immediately. Setting credits to unlimited automatically clears any existing refill settings. Changes propagate instantly but may take up to 30 seconds to reach all edge regions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's contradicting itself, if it takes 30s, then it doesn't propagate instantly
| @@ -0,0 +1,20 @@ | |||
| type: object | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wdym, you omitted it entirely here, right? or what am I missing?
I agree, I don't want to pollute our response too much
Graphite Automations"Post a GIF when PR approved" took an action on this PR • (11/03/25)1 gif was posted to this PR based on Andreas Thomas's automation. |
eed7ae0 to
d20a48c
Compare
53c3ced to
139d760
Compare
- Add Credits and CreditsRefill schema definitions - Add CreditOperation and CreditInterval enums - Add updateCredits endpoints for keys and identities - Update key and identity schemas to include credits field - Add UpdateCredits and UpdateCreditsRefill request/response types - Update generated OpenAPI specs
d20a48c to
b7c600b
Compare
139d760 to
ab009c0
Compare


What does this PR do?
This cleans up the openapi spec for the credits, so they can be used by both keys and credits
Doesn't pass any tests either but its fine as we are using this as base for the next pr
Type of change
How should this be tested?
Please double check if the schema makes sense in regards to nullability.
The api will throw a build error since the types got changed which is fixed in the next big pr
Checklist
Required
pnpm buildpnpm fmtconsole.logsgit pull origin mainAppreciated